package com.lovo.homework7_14ATM;

import javax.swing.*;
import java.awt.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

public class ATMmain extends JFrame  {
    private ArrayList<Users> userList =new ArrayList<Users>();

    private LoginPanel loginPanel = new LoginPanel(this,userList);
    private DepositPanel depositPanel = new DepositPanel(this);
    private MenuPanel menuPanel = new MenuPanel(this);
    private QueryPanel queryPanel = new QueryPanel(this);
    private WithdrawPanel withdrawPanel = new WithdrawPanel(this);
    private ModifyPanel modifyPanel = new ModifyPanel(this);
    private  TransferPanel transferPanel= new TransferPanel(this);
    private RecordTest recordTest =new RecordTest();

    private JLabel jLabelQuery;

    private Users loginUser;

    private CardLayout cardLayout = new CardLayout();

    private Image bgImage = util.Util.getImage("/images/background.jpg");

    private int person;

    //无参构造函数  设置窗口及属性
    public ATMmain() {
        init();
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImage, 0, 0, 1024, 768, this);
            }
        });
        util.FileChange.ObjectToBinary("111.dat",this.getUserList());

        this.setLayout(cardLayout);
        this.add("loginPanel",loginPanel);
        this.add("menuPanel",menuPanel);
        this.add("depositPanel",depositPanel);
        this.add("withDrawPanel",withdrawPanel);
        this.add("queryPanel",queryPanel);
        this.add("modifyPanel",modifyPanel);
        this.add("transferPanel",transferPanel);

        this.setSize(1024, 768);
        this.setTitle("中国银行客户端");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    //得到所有子页面的情况
    public DepositPanel getDepositPanel() {
        return depositPanel;
    }

    public LoginPanel getLoginPanel() {
        return loginPanel;
    }

    public MenuPanel getMenuPanel() {
        return menuPanel;
    }

    public QueryPanel getQueryPanel() {
        return queryPanel;
    }

    public WithdrawPanel getWithdrawPanel() {
        return withdrawPanel;
    }

    public ModifyPanel getModifyPanel() {
        return modifyPanel;
    }

    public TransferPanel getTransferPanel() {
        return transferPanel;
    }

    //获取登录的人set、get函数
    public Users getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(Users loginUser) {
        this.loginUser = loginUser;
    }

    public int getPerson() {
        return person;
    }

    public void setPerson(int person) {
        this.person = person;
    }

    //获取集合的set、get函数
    public ArrayList<Users> getUserList() {
        return userList;
    }

    public void setUserList(ArrayList<Users> userList) {
        this.userList = userList;
    }

    //获取标签的set、get函数
    public JLabel getjLabelQuery() {
        return jLabelQuery;
    }

    public void setjLabelQuery(JLabel jLabelQuery) {
        this.jLabelQuery = jLabelQuery;
    }

    //方法

    //初始化用户信息集合
    public void init(){
        userList.add(new Users("wanger","123123",6000));
        userList.add(new Users("zhangsan","456456",5000));
        userList.add(new Users("lisi","444444",5500));
        userList.add(new Users("xiaowu","555555",10000));
        userList.add(new Users("zhaoliu","666666",12000));
   //转文件
//    util.FileChange.ObjectToBinary("111.dat",this.userList);
    //转对象
    this.userList =(ArrayList) util.FileChange.BinaryToObject("111.dat");


//        System.out.println(aaaa);
//        System.out.println(this.userList);

    }

    //在有main函数的类里面写，不然每次都要被初始化
    public void balance(){


       this.getQueryPanel().getjLabel2().setText(this.getLoginUser().getMoney()+"");


//        getQueryPanel().getjLabel2().setText(getLoginUser().getMoney()+"");
    }

    public void switchPanel(String name){
        cardLayout.show(this.getContentPane(),name);
    }

    public static void main(String[] args) {

        ATMmain aaaa=    new ATMmain();

    }
}
